package jk.zmn.socket.tcp;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketException;
import java.util.Scanner;

/**
 * @author 张梦楠
 * @Title: ${file_name}
 * @Package ${package_name}
 * @Description: ${todo}
 * @date 2018/5/3011:37
 * @blog www.itzmn.com
 */
public class Client {
     public static void main(String[] args) throws Exception {

         //创建一个客户端
         Socket socket = new Socket("localhost", 8888);

         while (true){
             //准备数据，
             String msg = "djflk安防科技奥斯卡\n";

             OutputStream outputStream = socket.getOutputStream();

             Scanner scanner = new Scanner(System.in);
             String next = scanner.next();

             BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(outputStream);
             bufferedOutputStream.write(next.getBytes());
             bufferedOutputStream.flush();
             //socket.shutdownOutput();


             BufferedInputStream bufferedInputStream = new BufferedInputStream(socket.getInputStream());
             ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();

             int readsize=0;

             byte[] data = new byte[10];

             while ((readsize = bufferedInputStream.read(data))>0){
                 byteArrayOutputStream.write(data,0,readsize);
             }
             System.out.println("服务器给我的回应："+byteArrayOutputStream.toString());
         }
     }







}
